home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume91 / utilitys / browser1 / part01 / vollist.c < prev   
C/C++ Source or Header  |  1991-03-25  |  2KB  |  66 lines

  1. #include <libraries/dosextens.h>
  2. #include <stdio.h>
  3. #ifdef DEBUG
  4. #include "debug.h"
  5. #endif
  6. /* Fakes an Examine/ExNext interface to the device list. Call OpenVolList
  7.  * first, then ReadVolList(fib), and finally CloseVolList. This last is
  8.  * a dummy, but it's handy if you want to be safe and put a forbid/permit
  9.  * around the whole thing.
  10.  */
  11.  
  12. #define toAPTR(b) ((b)<<2)
  13. #define toBPTR(a) ((a)>>2)
  14.  
  15. struct DeviceList *list;
  16.  
  17. void OpenVolList(void)
  18. {
  19.     extern struct DosLibrary *DOSBase;
  20.     struct RootNode *root;
  21.     struct DosInfo *info;
  22.  
  23.     root = (struct RootNode *)DOSBase -> dl_Root;
  24.     info = (struct DosInfo *)toAPTR(root->rn_Info);
  25.     list = (struct DeviceList *)toAPTR(info->di_DevInfo);
  26. }
  27.  
  28. int ReadVolList(struct FileInfoBlock *fib)
  29. {
  30.     struct DeviceList *next;
  31.  
  32.     while(list) {
  33.         next = (struct DeviceList *)toAPTR(list->dl_Next);
  34.         if(list->dl_Type == DLT_VOLUME ||
  35.            list->dl_Type == DLT_DIRECTORY) {
  36.             char *ptr;
  37.             int count;
  38.             ptr = (char *)toAPTR((BPTR)list->dl_Name);
  39.             count = *ptr++;
  40.             if(count > 106)
  41.                 count = 106;
  42.             strncpy(fib->fib_FileName, ptr, count);
  43.             fib->fib_FileName[count++] = ':';
  44.             fib->fib_FileName[count] = 0;
  45.             if(strcmp(fib->fib_FileName, "RAM Disk:") == 0)
  46.                 strcpy(fib->fib_FileName, "RAM:");
  47.             fib->fib_DiskKey = 0;
  48.             fib->fib_DirEntryType = list->dl_Type;
  49.             fib->fib_Protection = 0;
  50.             fib->fib_EntryType = list->dl_Type;
  51.             fib->fib_Size = 0;
  52.             fib->fib_NumBlocks = 0;
  53.             fib->fib_Date = list->dl_VolumeDate;
  54.             fib->fib_Comment[0] = 0;
  55.             list = next;
  56.             return 1;
  57.         }
  58.         list = next;
  59.     }
  60.     return 0;
  61. }
  62.  
  63. void CloseVolList(void)
  64. {
  65. }
  66.